using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class RefAreaMap : EntityTypeConfiguration<RefArea>
	{
		public RefAreaMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.AreaCode)
				.HasMaxLength(10);
				
			this.Property(t => t.AreaName)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("RefAreas");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.AreaCode).HasColumnName("AreaCode");
			this.Property(t => t.AreaName).HasColumnName("AreaName");
			this.Property(t => t.CityId).HasColumnName("CityId");

			// Relationships
			this.HasOptional(t => t.RefCity)
				.WithMany(t => t.RefAreas)
				.HasForeignKey(d => d.CityId);
				
		}
	}
}

